package com.maxqaq.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @program: bus_manage
 * @description:
 * @author: max-qaq
 * @create: 2021-12-20 23:46
 **/

@Data
@NoArgsConstructor
public class Result<T> implements Serializable {
    private int code;

    private String message;

    private T data;

    public Result(int code, String message){
        this.code = code;
        this.message = message;
    }

    /**
     * 成功
     */
    public static <T> Result<T> SUCCESS(T data){
        Result<T> result= new Result<T>();
        result.setData(data);
        result.setCode(ResultMsgEnum.SUCCESS.getValue());
        result.setMessage(ResultMsgEnum.SUCCESS.getMessage());
        return result;
    }
    /**
     * 失败
     */
    public static <T> Result<T> FAIL(T data){
        Result<T> result= new Result<T>();
        result.setData(data);
        result.setCode(ResultMsgEnum.FAIL.getValue());
        result.setMessage(ResultMsgEnum.FAIL.getMessage());
        return result;
    }
    /**
     * 授权失败
     */
    public static <T> Result<T> AUTH_ERROR(T data){
        Result<T> result= new Result<T>();
        result.setData(data);
        result.setCode(ResultMsgEnum.AUTH_ERROR.getValue());
        result.setMessage(ResultMsgEnum.AUTH_ERROR.getMessage());
        return result;
    }
    /**
     * 服务器忙
     */
    public static <T> Result<T> SERVER_BUSY(T data){
        Result<T> result= new Result<T>();
        result.setData(data);
        result.setCode(ResultMsgEnum.SERVER_BUSY.getValue());
        result.setMessage(ResultMsgEnum.SERVER_BUSY.getMessage());
        return result;
    }
    /**
     * 数据库操作失败
     */
    public static <T> Result<T> DATABASE_OPERATION_FAILED(T data){
        Result<T> result= new Result<T>();
        result.setData(data);
        result.setCode(ResultMsgEnum.DATABASE_OPERATION_FAILED.getValue());
        result.setMessage(ResultMsgEnum.DATABASE_OPERATION_FAILED.getMessage());
        return result;
    }

}

